6. Linux Installation and Programming of CodeWarrior®



This chapter explains the CodeWarrior Professional for Linux system requirements, how to install the CodeWarrior software, and walks you through the creation of a console application. The topics in this chapter are:


Linux System Requirements

The CodeWarrior IDE requires the following hardware and software:

Table 6.1 Linux Requirements

Hardware
Intel® Pentium® or AMD K6®-class microprocessor, at least 64 megabytes of RAM, CD-ROM drive
Software
Red Hat® Linux for x86 version 5.2 or later, an X11-R5 display server
Other
40 MB free hard disk space


Installing CodeWarrior on Linux

The installation software on the CodeWarrior Professional for Linux CD-ROM installs all the necessary components you will need to use CodeWarrior.

There are a couple things you should be aware of before running the CodeWarrior install script. This section discusses the following topics:


Metrowerks Software License

Make sure you understand and agree with the software license before installing the software. The software license can be found on the root level of the CodeWarrior CD, in a file named LICENSE.


Software Package Contents

This software package should contain:

1. QuickStart Professional guide (optional on some products)

2. A CodeWarrior Professional CD-ROM

3. A registration card

4. Geekware catalog


NOTE:

If any of these items are missing, contact your local distributor or Metrowerks sales (sales@metrowerks.com).

EGCS for C++ Development

The stock Red Hat 5.2 C/C++ development installation does not contain everything needed to do C++ development with CodeWarrior. If you wish to use CodeWarrior for C++ development, you need to build and install your own copy of GCC or EGCS. It is best if this is done before you run the CodeWarrior install script. If you install EGCS after you have installed CodeWarrior, you will need to run the config_gcc_links.sh script manually so that CodeWarrior will be able to use it.


NOTE

This process will not remove the copy of gcc that is installed into /bin in the stock RedHat install.

In the Third_Party directory you will find the EGCS archive named egcs-1.1.2.tar.gz. Following are brief instructions on how to install it.


NOTE

You will likely need to be root for step three to work correctly.

1. Copy and decompress the archive.

Copy the egcs-1.1.2.tar.gz archive to your hard drive from the Third_Party directory on the CodeWarrior CD and decompress the archive.

2. Create the EGCS build directory.

Create a directory at the same level as the decompressed files called egcs-linux-build (or something similar).

3. Configure and install egcs.

cd to the build directory and enter the following commands:


  ./egcs-1.1.1/configure --enable-shared   make bootstrap
  make install

The two make steps will take some time. EGCS will be installed in /usr/local. Make sure that /usr/local comes before /bin in your PATH environment variable so that CodeWarrior finds the correct version of gcc. Typing which gcc or gcc -v after installation is complete will help you verify that CodeWarrior will find the correct version of gcc.

The latest EGCS C/C++ development releases can be found here:


  ftp://egcs.cygnus.com/pub/egcs/releases

For more info about egcs see:


  http://egcs.cygnus.com/

About DDD

We have included ddd, a visual front-end to the popular debugger, gdb. The ddd package is an optional install, and is not required by CodeWarrior to operate. However, the tutorial in this manual shows ddd windows. So, you may want to install ddd before taking the tutorial.


NOTE

You will likely need to be root for rpm to work correctly.

Copy the ddd-static-3.1.3-1.i386.rpm file to your hard drive from the Third_Party directory on the CodeWarrior CD and type the following command:


  rpm -i ddd-static-3.1.3-1.i386.rpm

To use ddd in your projects, see the section on third party debuggers under in the Targeting Linux manual.


Installing CodeWarrior

The CodeWarrior installer is a script named install-sh that installs the CodeWarrior IDE, and optionally the documentation and example projects. After installation is complete, a configuration script named config_gcc_links.sh creates soft links in CodeWarrior's directory that point to the directories that the gcc compiler looks in to find system header files.

Perform the following steps to install CodeWarrior onto your Linux system:

1. Launch the CodeWarrior installation program.

Insert the CodeWarrior Professional CD-ROM into your CD-ROM drive.

The install script can be found in root directory of the CodeWarrior Professional CD-ROM. Open a terminal window, cd to the directory you mounted the CD in, and run the installer like so:


  ./install-sh

TIP:

You can type "q" (without the quotes) at most prompts during the setup process to stop the installation and exit the installation program.

2. Read the software license.

The install script uses more to display the Metrowerks Software License. When the software license appears, please read it. If you agree, type "y" when you are asked if you accept the terms of the agreement.

3. Choose components to install.

There are two components that can be installed with this installer: the CodeWarrior IDE, and the CodeWarrior documentation and examples. The installer will ask you whether you want to install each one of these components. Type "y" to install a component, or "n" to skip it.

4. Select destination for the files.

By default, the installer will set the install path to /usr/local. The installer will ask you if you would like to change the installation directory. If you would like to change it, type "y"; otherwise, type "n" to continue.

If you answered "y", the installer will ask you to specify the full path of the directory into which you would like CodeWarrior to be installed.

5. After installation, read the release notes.

After installation, please read the release notes for the latest release information.

6. Install Adobe Acrobat.

CodeWarriors documentation is provided in both postscript format and acrobat PDF format. To view the acrobat PDF format, you must have Adobe Acrobat Reader installed on your system. Open the Documentation_Viewers directory in the CD-ROM directory and untar the arobat.reader.3021.installer.tar file to install Acrobat Reader.

To launch CodeWarrior you execute the cwide script found in the following location:


  metrowerks/CodeWarrior3.3/

You may wish to place a softlink to this script in a directory in your PATH. For example:


  ln -s /usr/local/metrowerks/CodeWarrior3.3/cwide /usr/local/bin/cwide

This way you can launch the IDE with the simple command: cwide from any terminal.

See the INSTALL readme file on your CodeWarrior Professional CD-ROM for more information.


What's Installed on Linux

Once the installation software is finished, you will have a cwpro directory installed on your system. Inside will be all the components you chose during installation. See INSTALL.LOG for information on what has been installed.


Creating a Linux Application

Follow these steps to create a simple console application.

1. Choose File `New Project.

The New Project dialog box appears.

2. Click the expansion control next to C_C++.

The C_C++ group opens.

3. Select C to select the C stationery.

4. Click OK.

The File Save dialog box appears.


NOTE

Check the Create Folder box in the New Project window to create a new folder for your project in the selected location

5. Enter the project name.

Type in a project name and give it file extension .mcp (we used test.mcp). This enables the IDE to recognize the project file as a CodeWarrior project.

6. Use the standard navigation controls to specify and save the new project.

7. Click Save.

The File Save window closes and a new project based on the chosen stationery is created.

8. Choose File`New.

A new empty editor window opens.

9. Choose File`Save .

The File Save dialog box appears. Name the file HelloWorld.c and click Save. The .c extension enables the IDE to recognize this file as a source code file.

10. Enter the sample code:


  /* helloworld.c */   #include <stdio.h>
  int main(void){
   printf("Hello world, this is CodeWarrior!\n");
   return 0;
  }

NOTE

A hello.c file exists in the new project. Please ignore the existing file and proceed with the steps to create a new file with the example code.

11. Select the Sources group in the project window

The Sources group is highlighted.

12. With the editor window frontmost, choose Project`Add Window.

The HelloWorld.c file is added to the project window.

13. Select the file named "hello.c" in the project window

The hello.c file is highlighted.

14. Choose Project`Remove Selected Items.

The hello.c file is removed from the project window.

15. Choose Project`Build.

The project compiles and the executable built.

16. Run the executable. It is named "a.out", and is in the same folder as the project.

The executable runs and the console output (shown in Figure 6.1) appears.


NOTE

This must be run from a terminal window or the File Manager.

Figure 6.1 Console output for Linux


Congratulations! You just created a program using the CodeWarrior IDE on Linux. For information on programming resources, please refer to "CodeWarrior Documentation."





Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: support@metrowerks.com
Copyright © 1999, Metrowerks Corp. All rights reserved.

Last updated: May 25, 1999 * Chris Magnuson * John Roseborough